package pl.polidea.imf.blackberry.ui;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import pl.polidea.imf.blackberry.service.IMFService;

public class EnterUserDataPopupScreen extends PopupScreen {
	
	LabelField title;
	EditField email;
	EditField password;

	ButtonField okButton;
	ButtonField closeButton;

	public EnterUserDataPopupScreen(final UiController controller) {
		super(new VerticalFieldManager(), Manager.VERTICAL_SCROLL);
		title = new LabelField("Login to IMF: ");
		email = new EditField("email: ", "");
		password = new EditField("password: ", "");

		okButton = new ButtonField("Save");
		closeButton = new ButtonField("Close");

		add(title);
		add(email);
		add(password);
		add(okButton);
		add(closeButton);

		okButton.setChangeListener(new FieldChangeListener() {

			public void fieldChanged(Field field, int context) {
				IMFService.getInstance().uiRequestRegistration(email.getText(), password.getText());
				controller.closeEnterUserData();
			}

		});

		closeButton.setChangeListener(new FieldChangeListener() {

			public void fieldChanged(Field field, int context) {
				IMFService.getInstance().uiRequestRegistrationCanceled();
				controller.closeEnterUserData();
			}

		});

	}
}
